import {AfterViewChecked, AfterViewInit, Component, OnInit} from '@angular/core';

@Component({
  selector: 'app-view-child',
  templateUrl: './view-child.component.html',
  styleUrls: ['./view-child.component.css']
})
export class ViewChildComponent implements OnInit, AfterViewInit, AfterViewChecked {

  message: string;

  constructor() {
  }

  ngOnInit() {
  }

  greeting(name: string) {
    setInterval(() => {
      console.log('hello' + name);
    }, 11500);

  }

  /*两个方法都是在视图组装完毕后执行，angular不允许在视图组装完毕后再对绑定的属性值进行更改*/
  ngAfterViewInit(): void {
    console.log('子组件的视图初始化完毕');
    /*采用以下方法进行不能更改的措施*/
    setTimeout(() => {
      this.message = 'xxx';
    }, 0);
  }

  ngAfterViewChecked(): void {
    console.log('子组件的视图变更检查化完毕');
  }
}
